package com.xoa.service.performance.leaderAssessment;

import com.xoa.dao.performance.ScoreItemMapper;
import com.xoa.dao.performance.leaderAssessment.ScoreItemLeaderMapper;
import com.xoa.model.performance.ScoreItem;
import com.xoa.model.performance.leaderAssessment.ScoreItemLeader;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ScoreItemLeaderService {
    @Autowired
    private ScoreItemLeaderMapper scoreItemMapper;


    public ToJson addScoreItem(ScoreItemLeader scoreItem) {
        ToJson toJson =new ToJson();
        int count=scoreItemMapper.insertSelective(scoreItem);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    public ToJson delScoreItem(Integer itemId) {
        ToJson toJson =new ToJson();
        int count=scoreItemMapper.deleteByPrimaryKey(itemId);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    public ToJson modifyScoreItem(ScoreItemLeader scoreItem) {
        ToJson toJson =new ToJson();
        int count=scoreItemMapper.updateByPrimaryKeySelective(scoreItem);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }

    public ToJson selScoreItem(ScoreItemLeader scoreItem,Integer page,Integer pageSize,Boolean useFlag) {
        ToJson<ScoreItemLeader> toJson =new ToJson();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page", pageParams);
        map.put("scoreItem", scoreItem);
        List<ScoreItemLeader> scoreItemList=scoreItemMapper.selectAllscoreItemBy(map);
        if (scoreItemList!=null){
            toJson.setObj(scoreItemList);
            toJson.setTotleNum(pageParams.getTotal());
            toJson.setFlag(0);
            toJson.setMsg("ok");
        }else{
            toJson.setFlag(1);
            toJson.setMsg("err");
        }
        return toJson;
    }
}
